package com.fly.video.downloader.content.history;

import com.fly.video.downloader.bean.Video;
import com.fly.video.downloader.core.os.AsyncTaskResult;
import ohos.app.Context;

import java.util.ArrayList;

public class HistoryReadTask implements Runnable {
    private Context context;
    private HistoryListener listener;
    private int page;
    private int PAGE_SIZE;

    public HistoryReadTask(Context context, HistoryReadTask.HistoryListener listener,int page, int PAGE_SIZE)
    {
        this.context = context;
        this.listener = listener;
        this.page=page;
        this.PAGE_SIZE=PAGE_SIZE;
    }
    @Override
    public void run() {
        try {
            ArrayList<Video> videosData =History.get(page, PAGE_SIZE);
            AsyncTaskResult<ArrayList<Video>> videos=new AsyncTaskResult(videosData);
            listener.onGot(videos.getResult());
        } catch (Throwable e) {
            listener.onError(e);
        }
    }

    public interface HistoryListener {
        void onGot(ArrayList<Video> videos);
        void onCanceled();
        void onError(Throwable e);
    }
}
